#pragma once
#include "kernel/feMesh.h"
#include "kernel/feElement.h"
#include "kernel/feMeshFunction.h"

#define MAX_ARRAY_SIZE 1000

class mfMesh : public feMesh
{
	friend class feSimple1dMeshFunction;

	feQuadraticElement1d Elements[MAX_ARRAY_SIZE];
	int				  ActElementsCount;
	fePoint			  Points[MAX_ARRAY_SIZE];
	int				  ActPointsCount;
	
	//std::list<feLinearElement1d> Elements;
	//std::vector<fePoint>		 Points;


protected:
	int ElIter;
	virtual feElement* First()					 { ElIter = 0; if(ActElementsCount > 0) return &Elements[0]; return 0; }
	virtual feElement* Next(feElement *iElem)	 { if(++ElIter != ActElementsCount) return &Elements[ElIter]; return 0; }
	virtual bool	   IsDone(feElement *iElem)	 { return ActElementsCount == 0 || ElIter == ActElementsCount; }
				
public:
			mfMesh() { ActElementsCount = ActPointsCount = 0;}
			mfMesh(mfMesh *iMesh, double iPointCoef=1);
			void CopyFrom(mfMesh *iMesh);
			void ScalePoints(double iCoef);
			void SplitElement(int iIndex, double iTau);
			void RebindElements();
	virtual fePoint&		GetNode(int iIndex) { return Points[iIndex]; }
	virtual int				NodesCount()		{ return ActPointsCount; }
	virtual ElementIterator GetIterator()		{ return ElementIterator(this);}
	virtual void			ClearMesh()			{ ActPointsCount = 0; ActElementsCount = 0; }	
	virtual void			PushElement(feElement *iElement);
	virtual void			PushNode(fePoint *iPoint) ;
	virtual bool			SaveToFile(char *iFname);
	virtual bool			LoadFromFile(char *iFname);
	virtual ~mfMesh() {}
};
